<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="身份证号" prop="idNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.idNumber" placeholder="请填写身份证号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="部门" prop="parts"
                :rules="[
                 ]">
              <el-input v-model="inputForm.parts" placeholder="请填写部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="安装日期" prop="installDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.installDate" placeholder="请填写安装日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下线日期" prop="offlineDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.offlineDate" placeholder="请填写下线日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料编码" prop="materialCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialCode" placeholder="请填写物料编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料名称" prop="materialName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.materialName" placeholder="请填写物料名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="规格型号" prop="specificationsModel"
                :rules="[
                 ]">
              <el-input v-model="inputForm.specificationsModel" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计量单位" prop="measuringUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.measuringUnit" placeholder="请填写计量单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="ABC分类" prop="classification"
                :rules="[
                 ]">
              <el-input v-model="inputForm.classification" placeholder="请填写ABC分类"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="待修说明" prop="unattendedInstructions"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unattendedInstructions" placeholder="请填写待修说明"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记时间" prop="registrationDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registrationDate" placeholder="请填写登记时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记人" prop="registrationPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registrationPeople" placeholder="请填写登记人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记人工号" prop="registrationPeopleNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registrationPeopleNumber" placeholder="请填写登记人工号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下线业务ID" prop="offlineBusinessId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.offlineBusinessId" placeholder="请填写下线业务ID"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          idNumber: '',
          parts: '',
          installDate: '',
          offlineDate: '',
          materialCode: '',
          materialName: '',
          specificationsModel: '',
          measuringUnit: '',
          classification: '',
          unattendedInstructions: '',
          registrationDate: '',
          registrationPeople: '',
          registrationPeopleNumber: '',
          offlineBusinessId: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建待修备件`
        } else if (method === 'edit') {
          this.title = '修改待修备件'
        } else if (method === 'view') {
          this.title = '查看待修备件'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartUnattendedDealwith/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.sparepartUnattendedDealwith)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartUnattendedDealwith/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>